package com.iamteer.a_hello;

import java.sql.Connection;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.junit.Test;

import com.iamteer.utils.JdbcUtil;

public class App {
	// 1. 使用 DbUtils 组件更新
	@Test
	public void testUpdate() throws Exception {
		String sql = "insert into admin(userName,pwd) values('celia','111111')";
		Connection con = JdbcUtil.getConnection();
//		Statement statement = con.createStatement();
//		statement.executeUpdate(sql);
		QueryRunner qr = new QueryRunner();
		qr.update(con, sql);
		con.close();
	}
	
	// 2. 使用 DbUtils 组件查询
	@Test
	public void testQuery() throws Exception{
		String sql = "select * from admin";
		Connection con = JdbcUtil.getConnection();
		QueryRunner qr = new QueryRunner();
		List<Admin> list = qr.query(con, sql, new BeanListHandler<Admin>(Admin.class));
		System.out.println(list);
		con.close();
	}
}
